package tt.com.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import tt.com.business.mapper.CremateMapper;
import tt.com.business.service.CremateService;
import tt.com.common.model.Cremate;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class CremateServicelmpl extends ServiceImpl<CremateMapper, Cremate> implements CremateService {

    @Override
    public ResponseEntity selectInformation(Date cremate) {
        if (cremate==null||cremate.equals("")){
            return new ResponseEntity("时间信息不可以为空", HttpStatus.INTERNAL_SERVER_ERROR);
        }
        //根据火化时间条件查询
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat ("yyyy-MM-dd");
        String format = simpleDateFormat.format(cremate);
        QueryWrapper<Cremate> wrapper = new QueryWrapper<>();

        wrapper.apply("date_format(cremate_time,'%Y-%m-%d') = '"+format+"'");
        List<Cremate> cremates = baseMapper.selectList(wrapper);
        return new ResponseEntity(cremates,HttpStatus.OK);
    }
}
